'''
''' Event handler for the init event
'''
Private Sub myCalendarInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Init
Dim calendar As System.Web.UI.WebControls.Calendar
calendar = CType(Me.Page.FindControlRecursively("calendar"), System.Web.UI.WebControls.Calendar)
AddHandler calendar.SelectionChanged, AddressOf CalendarControl_SelectionChanged
End Sub
'''
''' CalendarControl_SelectionChanged sets the text of the field value control
''' to the dated selected by the user
'''
Private Sub CalendarControl_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim calendar As System.Web.UI.WebControls.Calendar
calendar = CType(Me.Page.FindControlRecursively("calendar"), System.Web.UI.WebControls.Calendar)
If(Not IsNothing(calendar)) Then
${Date Field Control}.Text = calendar.SelectedDate.ToString()
Dim rec As New ${Parent Table}Record()
rec.Parse(calendar.SelectedDate.ToString(), ${${Parent Table}ClassName}.${Date Field Control})
Me.${Date Field Control}.Text = rec.Format(${${Parent Table}ClassName}.${Date Field Control})
End If
End Sub
'''
''' Override DataBind(),call mybase Databind() to populate the UI
''' controls using the DataSource
'''
Public Overrides Sub DataBind()
MyBase.DataBind()
If Not Me.Page.IsPostBack Then
If Me.DataSource Is Nothing Then
Return
End If
Me.${Date Field Control}.Text = Me.DataSource.Format(${${Parent Table}ClassName}.${Date Field Control})
if(Me.${Date Field Control}.Text.Length() > 0) Then
Dim dt As Date = Convert.ToDateTime(Me.${Date Field Control}.Text)
Dim calendar As System.Web.UI.WebControls.Calendar
calendar = CType(Me.Page.FindControlRecursively("calendar"), System.Web.UI.WebControls.Calendar)
If (Not IsNothing(calendar)) Then
calendar.SelectedDate = dt
calendar.VisibleDate = dt
End If
End If
End If
End Sub
'''
''' Set the text of the ${Date Field Control} and then call
''' MyBase.SaveData() to save the data
'''
Public Overrides Sub SaveData()
Dim calendar As System.Web.UI.WebControls.Calendar
calendar = CType(Me.Page.FindControlRecursively("calendar"), System.Web.UI.WebControls.Calendar)
If(not isnothing(calendar) AndAlso calendar.SelectedDate.Year <> 1 AndAlso ${Date Field Control}.Text = calendar.SelectedDate.ToString())Then
${Date Field Control}.Text = calendar.SelectedDate.ToString()
End If
' Call MyBase.SaveData()
MyBase.SaveData()
End Sub
|